//
//  remote_os.c
//  remote_controller
//
//  Created by fukai on 2018/11.
//  Copyright © 2018年 赛博智能车实验室. All rights reserved.
//

#include "remote_os.h"
#include "key.h"
#include "led.h"
#include "relay.h"
#include "oled.h"


//结构体初始化
remoteOsMessageNode remoteOsMessage = 
{
	.LedStatus = R_LED_OFF,
	.RelayStatus = RELAY_OFF,
	.OledStatus = STATUS_SHOW,
};




/********LED状态控制********/

//LED状态控制
//用于中断中
void LedStatusCtrl(void)
{
	switch(remoteOsMessage.LedStatus)
	{
		case R_LED_OFF:	//LED关闭
			LedOff();
			break;
		case R_LED_ALL_ON:	//LED打开
			LedOn();
			break;
		case R_LED_ALL_FLICKER: //LED闪烁
			LedFlicker(200);
			break;
		case R_LED_FLOW_SLOW:	//LED流水灯慢
			FlowLampOn(200);
			break;
		case R_LED_FLOW_FAST:	//LED流水灯快
			FlowLampOn(50);
			break;
	}
}


/********继电器状态控制********/

//继电器状态控制
//用于中断中
void RelayStatusCtrl(void)
{ 
	switch(remoteOsMessage.RelayStatus)
	{
		case RELAY_OFF:
			RelayOff();
			break;
		case RELAY_ON:
			RelayOn();
			break;
	}
}

/********系统总控制********/

//功能选择
void FunctionSelection(void)
{
	KeyMessage.KeyValue = KeyScan();
	switch(KeyMessage.KeyValue)
	{
		case KEY_NULL:
			break;
		case KEY_OLED:
			OledCls();
			remoteOsMessage.OledStatus++;
			if(remoteOsMessage.OledStatus > STATUS_SHOW)
			{
				remoteOsMessage.OledStatus = INFO_SHOW;
			}
			break;
		case KEY_LED:
			LedOff();
			OledCls();
			remoteOsMessage.LedStatus++;
			if(remoteOsMessage.LedStatus > R_LED_FLOW_FAST)
			{
				remoteOsMessage.LedStatus = R_LED_OFF;
			}
			break;
		case KEY_RELAY:
			OledCls();
			remoteOsMessage.RelayStatus++;
			if(remoteOsMessage.RelayStatus > RELAY_ON)
			{
				remoteOsMessage.RelayStatus = RELAY_OFF;
			}
			break;
		case KEY_BEEP:
			OledCls();
			break;
	}
}

//图像显示
void OledDisplay(void)
{
	switch(remoteOsMessage.OledStatus)
	{
		case INFO_SHOW:
			OledShow6x8Str(10,2,"Name: JinMinYi");
			OledShow6x8Str(10,3,"ID:   1600301206");
			break;
		case STATUS_SHOW:
			switch(remoteOsMessage.LedStatus)
			{
				case R_LED_OFF:
					OledShow6x8Str(10,1,"LED OFF!");
					break;
				case R_LED_ALL_ON:
					OledShow6x8Str(10,1,"LED ON!");
					break;
				case R_LED_ALL_FLICKER:
					OledShow6x8Str(10,1,"LED FLICKER!");
					break;
				case R_LED_FLOW_SLOW:
					OledShow6x8Str(10,1,"LED FLOW SLOW!");
					break;
				case R_LED_FLOW_FAST:
					OledShow6x8Str(10,1,"LED FLOW FAST!");
					break;
			}
			switch(remoteOsMessage.RelayStatus)
			{
				case RELAY_OFF:
					OledShow6x8Str(10,3,"RELAY OFF!");
					break;
				case RELAY_ON:
					OledShow6x8Str(10,3,"RELAY ON!");
					break;
			}
			break;
	}
}


//系统控制部分
void RemoteOs(void)
{
	FunctionSelection();
	OledDisplay();
}


